using System;
using XEvolve.Core.Runtime.Attributes;
using XEvolve.Repository.Internal;
using System.Linq;

namespace XEvolve.Repository.Core
{
    public class XRepository
    {
        private static readonly MemoryBasedRepository defaultRepository;
        private readonly IRepository[] exRepositories;

        static XRepository()
        {
            defaultRepository = new MemoryBasedRepository();
        }

        public XRepository([Extensions("xevolve.repository.ex")] IRepository[] exRepositories)
        {
            this.exRepositories = exRepositories;
        }

        public IRepository GetRepositoryByType(Type repositoryType)
        {
            return exRepositories.SingleOrDefault(repo => repo.GetType() == repositoryType);
        }

        public static IRepository GetDefaultRepository()
        {
            
            return defaultRepository;
        }
    }
}